//
//  LLGMainViewController.swift
//  Weibo30LLG
//
//  Created by 李龙 on 16/8/8.
//  Copyright © 2016年 lilong. All rights reserved.
//

import UIKit

class LLGMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        let tabbar = LLGTabBar()
        
        tabbar.llgDelegate = self
        
        //闭包回调
        tabbar.composeClosure = { [weak self] in
            
//            print("我是闭包回调过来的")
            //进入发微博界面
            self?.pushComposeVC()
        }
        
        setValue(tabbar, forKey: "tabBar")
        
        //添加子控制器
        addChildViewController(LLGHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(LLGMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(LLGDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(LLGProfileTableViewController(), imageName: "tabbar_profile", title: "我的")
        
    }
    
    // MARK: --添加子控制器,重载
    func addChildViewController(childController: UIViewController, imageName: String, title: String) {
        
        //设置标题
        childController.title = title
        
        //设置图片
        childController.tabBarItem.image = UIImage(named: imageName)
        //渲染模式
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置选中状态文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        //设置字体大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: .Normal)
        
     
        //创建导航控制器
        let navVc = UINavigationController(rootViewController: childController)
        
        //添加子控制器
        addChildViewController(navVc)
    }
    
    // MARK: --进入发微博控制器
    private func pushComposeVC() {
    
        let composeVC = LLGComposeViewController()
        
        let nav = UINavigationController(rootViewController: composeVC)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    

}

extension LLGMainViewController: LLGTabBarDelegate {

    // MARK: --tabbar代理方法
    func didSelectedComposeButton() {
        
//        print("我是代理回调过来的")
    }
    
}
